package com.shoe.controller;

import com.shoe.pojo.AdminAftersalePojo;
import com.shoe.service.UserAftersaleService;
import com.shoe.util.DateConversion;
import com.shoe.util.ResultUtil;
import com.shoe.vo.ResponseResult;
import com.shoe.vo.UserAftShowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("user")
public class UserAftersaleController {

    @Autowired
    UserAftersaleService userAftersaleService;

    @Autowired
    ResultUtil resultUtil;

    @GetMapping("aftersaler")
    public ResponseResult selectUserAftersaleByCondition(@RequestParam(defaultValue = "1") Integer currPage, @RequestParam(defaultValue = "5") Integer pageSize, Integer userId, String aftersaleSolve) {
        return userAftersaleService.selectUserAftersaleByCondition(currPage, pageSize, userId, aftersaleSolve);
    }

    @GetMapping("selectUAftShow")
    public ResponseResult selectUAftShow(Integer userId, Integer orderId) {
        UserAftShowVo selectUAftShow = userAftersaleService.selectUAftShow(userId, orderId);
        if (null != selectUAftShow) {
            return resultUtil.getResponseResult(0, "", selectUAftShow);
        } else {
            return resultUtil.getResponseResult(2, "查询失败");
        }
    }

    @GetMapping("addUAft")
    public ResponseResult addUAft(Integer orderId, String aftSaleSolve, String aftRequi) {

        DateConversion dateConversion = new DateConversion();

        int addUAft = userAftersaleService.addUAft(orderId, aftSaleSolve, aftRequi, dateConversion.Data2Sting());
        if (addUAft > 0) {
            return resultUtil.getResponseResult(0, "");
        } else {
            return resultUtil.getResponseResult(2, "添加失败");
        }
    }

    @GetMapping("selectUAftHave")
    public ResponseResult selectUAftHave(Integer aftOrderId) {

        List<AdminAftersalePojo> uAftHaveList = userAftersaleService.selectUAftHave(aftOrderId);
        System.out.println(uAftHaveList.toString());

        if (null != uAftHaveList && uAftHaveList.size() > 0) {
            return resultUtil.getResponseResult(0, "已添加");
        } else {
            return resultUtil.getResponseResult(2, "");
        }
    }
}

